export default {
  data() {
    return {
      location: '正在获取位置...',
      shortLocation: '定位中...',
      stations: [
        {
          name: '人民广场站',
          distance: 500,
          lines: [
            {
              number: '908',
              destination: '洋河',
              eta: 8,
              stops: 4,
              distance: 3.6
            },
            {
              number: '123',
              destination: '火车站',
              eta: 5,
              stops: 2,
              distance: 1.8
            }
          ]
        },
        {
          name: '中山公园站',
          distance: 800,
          lines: [
            {
              number: '456',
              destination: '动物园',
              eta: 10,
              stops: 5,
              distance: 4.2
            }
          ]
        }
      ],
      selectedCity: ''
    }
  },
  onLoad() {
    this.getLocation();
  },
  methods: {
    async getLocation() {
      try {
        const res = await uni.getLocation({
          type: 'wgs84'
        });
        this.location = `纬度：${res.latitude}, 经度：${res.longitude}`;
        const city = await this.getCityName(res.latitude, res.longitude);
        this.shortLocation = city || '当前位置';
        this.getNearbyStations(res.latitude, res.longitude);
      } catch (err) {
        console.error('获取位置失败', err);
        this.location = '获取位置失败';
        this.shortLocation = '定位失败';
      }
    },
    async getCityName(lat, lng) {
      return '上海市';
    },
    async getNearbyStations(lat, lng) {
      this.stations = [
        {
          name: '人民广场站',
          distance: 500,
          lines: [
            {
              number: '908',
              destination: '洋河',
              eta: 8,
              stops: 4,
              distance: 3.6
            },
            {
              number: '123',
              destination: '火车站',
              eta: 5,
              stops: 2,
              distance: 1.8
            }
          ]
        },
        {
          name: '中山公园站',
          distance: 800,
          lines: [
            {
              number: '456',
              destination: '动物园',
              eta: 10,
              stops: 5,
              distance: 4.2
            }
          ]
        }
      ];
    },
    goToCitySelect() {
      uni.navigateTo({
        url: '/pages/city/city'
      });
    },
    setSelectedCity(city) {
      this.selectedCity = city;
    }
  }
}